package de.jmda.util.gui.fx;

import java.io.File;

import javafx.scene.image.Image;

import javax.lang.model.element.TypeElement;

import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import de.jmda.MarkerAnnotationType;
import de.jmda.gui.ImageFilenameFactory;
import de.jmda.mproc.LaunchConfiguration;
import de.jmda.mproc.TypeElementDictionary;
import de.jmda.mproc.TypeElementDictionaryDefaultProcessor;
import de.jmda.mproc.TypeElementDictionarySingleton;

@MarkerAnnotationType
public class JUTImageFactory
{
	private final static Logger LOGGER = Logger.getLogger(JUTImageFactory.class);

	private static TypeElementDictionary TYPE_ELEMENT_DICTIONARY;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
		TYPE_ELEMENT_DICTIONARY = TypeElementDictionarySingleton.instance();

		File file =
				new File(
						"src/test/java/" +
						JUTImageFactory.class.getPackage().getName().replaceAll("\\.", "/") +
						"/" + JUTImageFactory.class.getSimpleName() + ".java");

		if (false == file.exists())
		{
			throw new RuntimeException(
					"file " + file.getAbsolutePath() + " does not exist");
		}

		LaunchConfiguration launchConfiguration = new LaunchConfiguration();
		launchConfiguration.files.add(file);

		TypeElementDictionaryDefaultProcessor.launch(launchConfiguration);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void test()
	{
		for (TypeElement typeElement : TYPE_ELEMENT_DICTIONARY.getAll())
		{
			LOGGER.info("element in type element dictionary: " + typeElement);
			LOGGER.info(
					"image file name: " +
					ImageFilenameFactory.getImageFilename(typeElement, "png"));
			Image image = ImageFactory.getImage(typeElement, "png");
			if (image == null)
			{
				LOGGER.error("failure finding image for " + typeElement);
			}
		}

		LOGGER.info(
				"number of elements in type element dictionary: " +
				TYPE_ELEMENT_DICTIONARY.getAll().length);
	}
}